// pages/page/goods_class/goods_class.js
var request_api = require('../../../utils/require_api.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type_data: [],
    active: 0,
    scrollTop: 0,
    typepic: "https://cdzhongdan.oss-cn-shenzhen.aliyuncs.com/public_pic/%E7%94%B7%E8%A3%85%E5%A5%B3%E8%A3%85%E4%BC%9A%E5%9C%BA/%E7%94%B7%E8%A3%85%E4%BC%9A%E5%9C%BA.png",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let id = options.id;
    if (id == 1) {
      wx.setNavigationBarTitle({
        title: '男装会场'
      })
      this.get_styledata('男', '', '', id);
    } else if (id == 2) {
      wx.setNavigationBarTitle({
        title: '女装会场'
      })
      this.get_styledata('女', '', '', id);
    } else if (id == 3) {
      wx.setNavigationBarTitle({
        title: '春季新品'
      })
      this.get_styledata('', '1', '', id);
    } else if (id == 4) {
      wx.setNavigationBarTitle({
        title: '鞋包专区'
      })
      this.get_styledata('', '', '鞋包', id);
    }

  },

  get_styledata(type, sex, yearseason, id) {
    //  请求活动专区的数据
    var that = this;
    request_api.request(
      'select_bygoods', //需要传给wxrequest.js 的 url
      {
        "type": type,
        "sex": sex,
        "yearseason": yearseason
      }, //需要传的 data
      function(res) {
        if (id == 1) {
          that.data.typepic = "https://cdzhongdan.oss-cn-shenzhen.aliyuncs.com/public_pic/%E7%94%B7%E8%A3%85%E5%A5%B3%E8%A3%85%E4%BC%9A%E5%9C%BA/%E7%94%B7%E8%A3%85%E4%BC%9A%E5%9C%BA.png";
        } else if (id == 2) {
          that.data.typepic = "https://cdzhongdan.oss-cn-shenzhen.aliyuncs.com/public_pic/%E7%94%B7%E8%A3%85%E5%A5%B3%E8%A3%85%E4%BC%9A%E5%9C%BA/%E5%A5%B3%E8%A3%85%E4%BC%9A%E5%9C%BA.png";
        } else if (id == 3) {
          that.data.typepic = "https://cdzhongdan.oss-cn-shenzhen.aliyuncs.com/public_pic/%E7%94%B7%E8%A3%85%E5%A5%B3%E8%A3%85%E4%BC%9A%E5%9C%BA/%E4%B8%8A%E6%96%B0.jpg";
        } else {

        }
        that.setData({
          typepic: that.data.typepic,
          type_data: res.data
        })
      },
      function() {
        console.log("錯誤");
      },
    )
  },
 

  immediate_purchase(res){
    wx.navigateTo({
      url: '../goods_details/goods_details?style_id=' + res.currentTarget.dataset.goods_id,
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})